home *** CD-ROM | disk | FTP | other *** search
- ===========================================================================
- BBS: The Abacus * HST/DS * Potterville, MI
- Date: 05-15-93 (13:55) Number: 160
- From: GAINES WRIGHT Refer#: NONE
- To: ZACH HANNA Recvd: NO
- Subj: edstrwin() 1 of 3 Conf: (36) C Language
- ---------------------------------------------------------------------------
- ZH>I am having serious difficulty writing a text input function. I am
- ZH>limited in space, so I would like there to be a limit on the amount of
- ZH>characters which are displayed at one time, with arrows denoting wether
- ZH>or not there was text scrolled off either end.
-
- ZH>Here is an example:
-
- ZH>(Full string) "This is just a sample text string"
- ZH>(Shown on screen) .ust a sample tex.
-
- This is a quick hack of my edstrtxt() function to do the above. Use
- at your own risk.
- Gaines Wright
-
- //Written for TC by Gaines Wright
- //Donated to the public domain
-
- #include <dos.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <conio.h>
- #include <mem.h>
- #include <ctype.h>
-
- //Definitions for edstrwin() type parameter
- #define STRING 0 //Allows only alphanumeric.
- #define INT 1 //Allows only digits.
- #define FLOAT 2 //Allows only digits & one '.'.
- #define ONLY 3 //Allows only the chars contained in chars_allowed.
-
- //Reads the keyboard. Returns minus numbers for double char keys
- int getkey(void)
- {
- int c;
- if(!(c=getch()))
- c=-getch();
- return(c);
- }
-
- void beep(void)
- {
- sound(800);
- delay(10);
- nosound();
- }
-
- //Edits a string at xpos, ypos, in a window winlen long, in the current text
- //attribute, accepts max_chars number of chars. If using any type except
- //ONLY, *chars_allowed is not active. Be sure when passing an empty string
- //for new input to do a string[0]='\0'; before calling or you will get
- //garbage on the screen. Also do not allow the string to line wrap or the
- //editing keys will fail.
-
- int edstrwin(char *string,int xpos,int ypos,int winlen,
- int max_chars,int type,char *chars_allowed)
- {
- int c,strpos=0,str_len,beep_break;
- char *temp; //Holds the portion of string that appears in window
- if((temp=(char *)malloc(strlen(string)+1))==NULL)
- {
- cputs("Memory error in edstrwin()");
- exit(-1);
- }
- static char insert=0; //Change this to a 1 to start up in insert mode
- //continued next message
-
- ---
- ■ SLMR 2.1a ■ On a clear disk you can seek forever
-
- --- DCI/Chauncy 0.7b
- * Origin: Bird Lake - (813)265-3256 (1:377/14.0)
- SEEN-BY: 1/211 11/2 4 13/13 101/1 108/89 109/25 110/69 114/5 123/19 124/1
- SEEN-BY: 153/752 154/40 77 157/2 159/100 125 575 950 203/23 209/209 261/1023
- SEEN-BY: 280/1 390/1 396/1 5 15 2270/1 2440/5 3603/20
-